home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / misc / o-z / x-windows / mesa-amiwin / src / xmesap.h < prev   
Encoding:
C/C++ Source or Header  |  1995-11-30  |  9.2 KB  |  321 lines

  1. /* xmesaP.h */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25. $Id: xmesaP.h,v 1.19 1995/11/30 00:51:40 brianp Exp $
  26.  
  27. $Log: xmesaP.h,v $
  28.  * Revision 1.19  1995/11/30  00:51:40  brianp
  29.  * added casts to DITHER_HPCR macro to silence Sun compiler warnings
  30.  *
  31.  * Revision 1.18  1995/11/30  00:20:39  brianp
  32.  * added new PF_GRAYSCALE mode
  33.  *
  34.  * Revision 1.17  1995/10/30  15:14:21  brianp
  35.  * replaced Current variable with XMesa
  36.  *
  37.  * Revision 1.16  1995/10/19  15:50:38  brianp
  38.  * added rgb_flag and share_list fields
  39.  *
  40.  * Revision 1.15  1995/10/17  21:38:17  brianp
  41.  * many changes for new X/Mesa device driver
  42.  *
  43.  * Revision 1.14  1995/09/15  18:49:25  brianp
  44.  * added rowimage span buffer
  45.  *
  46.  * Revision 1.13  1995/08/24  22:07:40  brianp
  47.  * added swapbytes field
  48.  *
  49.  * Revision 1.12  1995/07/24  19:02:30  brianp
  50.  * new comments for PF_DITHER and its tables
  51.  *
  52.  * Revision 1.11  1995/05/31  14:59:55  brianp
  53.  * shm field not dependent on SHM symbol
  54.  *
  55.  * Revision 1.10  1995/05/22  20:59:34  brianp
  56.  * Release 1.2
  57.  *
  58.  * Revision 1.9  1995/04/17  13:57:14  brianp
  59.  * changed to support GLXPixmaps
  60.  *
  61.  * Revision 1.8  1995/03/30  21:10:12  brianp
  62.  * replaced colorpacking with pixelformat
  63.  *
  64.  * Revision 1.7  1995/03/22  21:38:17  brianp
  65.  * *** empty log message ***
  66.  *
  67.  * Revision 1.6  1995/03/13  20:56:23  brianp
  68.  * removed drawbuffer and readbuffer fields
  69.  *
  70.  * Revision 1.5  1995/03/08  15:10:02  brianp
  71.  * added support for dd_logicop
  72.  * added dd_clear_index and dd_clear_color
  73.  *
  74.  * Revision 1.4  1995/03/07  14:21:36  brianp
  75.  * updated for new XSetForeground/GC scheme
  76.  *
  77.  * Revision 1.3  1995/03/04  19:25:29  brianp
  78.  * 1.1 beta revision
  79.  *
  80.  * Revision 1.2  1995/03/02  19:31:42  brianp
  81.  * added defines for FRONT_PIXMAP, BACK_PIXMAP, and BACK_XIMAGE
  82.  *
  83.  * Revision 1.1  1995/02/28  21:23:31  brianp
  84.  * Initial revision
  85.  *
  86.  */
  87.  
  88.  
  89. #ifndef XMESAP_H
  90. #define XMESAP_H
  91.  
  92.  
  93. #ifdef SHM
  94. #  include <X11/extensions/XShm.h>
  95. #endif
  96. #include "GL/xmesa.h"
  97. #include "context.h"
  98.  
  99.  
  100. /*
  101.  * This struct is used by xmesa[12].c and glx.c only!
  102.  */
  103.  
  104.  
  105.  
  106. struct xmesa_context {
  107.         struct gl_context *gl_ctx;    /* the core library context */
  108.  
  109.     GLboolean initialized;    /* Is this context initialized yet? */
  110.  
  111.         GLboolean rgb_flag;    /* In RGBA mode? */
  112.  
  113.         struct xmesa_context *share_list;
  114.  
  115.     Display *display;    /* the X11 display */
  116.     Visual *visual;        /* the X11 visual */
  117.  
  118.     GC gc1;            /* GC for infrequent color changes */
  119.     GC gc2;            /* GC for frequent color changes */
  120.     GC cleargc;        /* GC for clearing the color buffer */
  121.  
  122.         GLboolean swapbytes;    /* TRUE if byte-swapping is needed */
  123.  
  124.     GLuint db_state;    /* 0 = single buffered */
  125.                 /* BACK_PIXMAP = use Pixmap for back buffer */
  126.                 /* BACK_XIMAGE = use XImage for back buffer */
  127.  
  128.     Drawable frontbuffer;    /* either a window or pixmap */
  129.     Pixmap backpixmap;    /* back buffer Pixmap */
  130.     XImage *backimage;    /* back buffer XImage */
  131.  
  132.         Drawable buffer;    /* the current buffer, either equal to */
  133.                 /* frontbuffer, backpixmap or XIMAGE (None) */
  134.  
  135.     GLuint shm;        /* X Shared Memory extension status:    */
  136.                 /*    0 = not available            */
  137.                 /*    1 = XImage support available    */
  138.                 /*    2 = Pixmap support available too    */
  139. #ifdef SHM
  140.     XShmSegmentInfo shminfo;
  141. #endif
  142.  
  143.         XImage *rowimage;    /* Used for optimized span writing */
  144.  
  145.     GLuint width, height;    /* size of buffer */
  146.     GLuint depth;        /* bits per pixel (1, 8, 24, etc) */
  147.  
  148.         GLubyte red, green, blue; /* current drawing color */
  149.     unsigned long pixel;      /* current color index or RGBA pixel value */
  150.  
  151.     unsigned long clearpixel; /* pixel for clearing the color buffers */
  152.  
  153.     GLuint pixelformat;    /* Current pixel format */
  154.         GLuint dithered_pf;    /* Pixel format when dithering */
  155.         GLuint undithered_pf;    /* Pixel format when not dithering */
  156.  
  157.     /* For PF_TRUECOLOR */
  158.     GLint rmult, gmult, bmult, amult;    /* Multiplier */
  159.     GLint rshift, gshift, bshift, ashift;    /* Bit shifts */
  160.  
  161.     /* For PF_DITHER */
  162.     unsigned long color_table[256];        /* RGB -> pixel value */
  163.     GLubyte red_table[65536];        /* pixel value -> red */
  164.     GLubyte green_table[65536];        /* pixel value -> green */
  165.     GLubyte blue_table[65536];        /* pixel value -> blue */
  166. };
  167.  
  168.  
  169.  
  170. /* Values for XMesa->dest: */
  171. #define FRONT_PIXMAP    1
  172. #define BACK_PIXMAP    2
  173. #define BACK_XIMAGE    4
  174.  
  175.  
  176. /* Values for XMesa->pixelformat: */
  177. #define PF_INDEX    1    /* Color Index mode */
  178. #define PF_TRUECOLOR    2    /* TrueColor or DirectColor, any depth */
  179. #define PF_8A8B8G8R    3    /* a special case of PF_TRUECOLOR */
  180. #define PF_DITHER    4    /* Dithered RGB using a lookup table */
  181. #define PF_1BIT        5    /* monochrome dithering of RGB */
  182. #define PF_HPCR        6    /* HP Color Recovery (ad@lms.be 30/08/95) */
  183. #define PF_LOOKUP       7       /* alternative to PF_DITHER */
  184. #define PF_GRAYSCALE    8       /* Grayscale or StaticGray */
  185.  
  186.  
  187.  
  188. /*
  189.  * If pixelformat==PF_TRUECOLOR:
  190.  */
  191. #define PACK_RGB( R, G, B )        \
  192.     (   ((R) << XMesa->rshift)    \
  193.       | ((G) << XMesa->gshift)    \
  194.       | ((B) << XMesa->bshift) )
  195. #define PACK_RGBA( R, G, B, A )        \
  196.     (   ((R) << XMesa->rshift)    \
  197.       | ((G) << XMesa->gshift)    \
  198.       | ((B) << XMesa->bshift)    \
  199.       | ((A) << XMesa->ashift) )
  200.  
  201.  
  202.  
  203. /*
  204.  * If pixelformat==PF_1BIT:
  205.  */
  206. static int kernel1[4][4] = {  0*47,  9*47,  4*47, 12*47,
  207.                   6*47,  2*47, 14*47,  8*47,
  208.                  10*47,  1*47,  5*47, 11*47,
  209.                   7*47, 13*47,  3*47, 15*47 };
  210. #define DITHER_1BIT( X, Y, R, G, B )    \
  211.     ( ((int)(R)+(int)(G)+(int)(B)) > kernel1[(X)&3][(Y)&3] )
  212.  
  213.  
  214.  
  215. /*
  216.  * If pixelformat==PF_DITHER:
  217.  *
  218.  * Improved 8-bit RGB dithering code contributed by Bob Mercier
  219.  * (mercier@hollywood.cinenet.net).  Thanks Bob!
  220.  */
  221. #define _R    5
  222. #define _G    9
  223. #define _B    5
  224. #define _DX    4
  225. #define _DY    4
  226. #define _D    (_DX*_DY)
  227. #define _MIX(r,g,b)    (((r)*_G+(g))*_B+(b))
  228. /*#define _DITH(C,c,d)    (((unsigned)((_D*(C-1)+1)*c+d))/(_D*256))*/
  229. #define _DITH(C,c,d)    (((unsigned)((_D*(C-1)+1)*c+d)) >> 12)
  230.  
  231. #define MAXC    256
  232. static int kernel8[_DY][_DX] = {
  233.    { 0 * MAXC,  8 * MAXC,  2 * MAXC, 10 * MAXC},
  234.    {12 * MAXC,  4 * MAXC, 14 * MAXC,  6 * MAXC},
  235.    { 3 * MAXC, 11 * MAXC,  1 * MAXC,  9 * MAXC},
  236.    {15 * MAXC,  7 * MAXC, 13 * MAXC,  5 * MAXC},
  237. };
  238. static int __d;
  239. #define DITHER_8BIT( X, Y, R, G, B )            \
  240.     (__d = kernel8[(Y)&(_DY-1)][(X)&(_DX-1)],    \
  241.      XMesa->color_table[_MIX(_DITH(_R, (R), __d),    \
  242.                  _DITH(_G, (G), __d),    \
  243.                  _DITH(_B, (B), __d))])
  244.  
  245.  
  246. /*
  247.  * If pixelformat==PF_LOOKUP:
  248.  */
  249. #define _DITH0(C,c)    (((unsigned)((_D*(C-1)+1)*c)) >> 12)
  250. #define LOOKUP( R, G, B )                \
  251.      XMesa->color_table[_MIX(_DITH0(_R, (R)),    \
  252.                  _DITH0(_G, (G)),    \
  253.                  _DITH0(_B, (B)))]
  254.  
  255.  
  256. /*
  257.  * If pixelformat==PF_HPCR:
  258.  *
  259.  *      HP Color Recovery dithering               (ad@lms.be 30/08/95)
  260.  *      HP has on it's 8-bit 700-series computers, a feature called
  261.  *      'Color Recovery'.  This allows near 24-bit output (so they say).
  262.  *      It is enabled by selecting the 8-bit  TrueColor  visual AND
  263.  *      corresponding  colormap (see tkInitWindow) AND doing some special
  264.  *      dither.
  265.  */
  266. static short HPCR_DR[2][16] = {
  267.     { 16, -4,  1,-11, 14, -6,  3, -9, 15, -5,  2,-10, 13, -7,  4, -8},
  268.     {-15,  5,  0, 12,-13,  7, -2, 10,-14,  6, -1, 11,-12,  8, -3,  9} };
  269. static short HPCR_DG[2][16] = {
  270.     {-11, 15, -7,  3, -8, 14, -4,  2,-10, 16, -6,  4, -9, 13, -5,  1},
  271.     { 12,-14,  8, -2,  9,-13,  5, -1, 11,-15,  7, -3, 10,-12,  6,  0} };
  272. static short HPCR_DB[2][16] = {
  273.     {  6,-18, 26,-14,  2,-22, 30,-10,  8,-16, 28,-12,  4,-20, 32, -8},
  274.     { -4, 20,-24, 16,  0, 24,-28, 12, -6, 18,-26, 14, -2, 22,-30, 10} };
  275.  
  276. static int _hpcr_x, _hpcr_y;
  277. #define DITHER_HPCR( X, Y, R, G, B )                                \
  278.   (_hpcr_x=((X)%16), _hpcr_y=((Y)%2),                                   \
  279.    ( (((((R) >= 48)  ? ((int)(R) - 16) : ((int)(R)/2 + 16)) + HPCR_DR[_hpcr_y][_hpcr_x]) & 0xE0)     \
  280.    |((((((G) >= 48)  ? ((int)(G) - 16) : ((int)(G)/2 + 16)) + HPCR_DG[_hpcr_y][_hpcr_x]) & 0xE0)>>3) \
  281.    | (((((B) >= 112) ? ((int)(B) - 32) : ((int)(B)/2 + 32)) + HPCR_DB[_hpcr_y][_hpcr_x])>>6) \
  282.    )                                                                 \
  283.   )
  284.  
  285.  
  286.  
  287. /*
  288.  * If pixelformat==PF_GRAYSCALE:
  289.  */
  290. #define GRAY_RGB( R, G, B )   XMesa->color_table[(R) + (G) + (B)]
  291.  
  292.  
  293.  
  294.  
  295. #define XIMAGE None
  296.  
  297.  
  298. /*
  299.  * Useful macros:
  300.  */
  301. #define OFFSET1( X, Y )   ((XMesa->height-(Y)-1) * XMesa->backimage->bytes_per_line + (X))
  302. #define OFFSET4( X, Y )   ((XMesa->height-(Y)-1) * XMesa->width + (X))
  303. #define FLIP(Y)  (XMesa->height-(Y)-1)
  304.  
  305.  
  306.  
  307.  
  308. extern XMesaContext XMesa;
  309.  
  310. extern void xmesa_alloc_back_buffer( XMesaContext c );
  311. extern void xmesa_setup_DD_pointers( void );
  312. extern points_func xmesa_get_points_func( void );
  313. extern line_func xmesa_get_line_func( void );
  314. extern polygon_func xmesa_get_polygon_func( void );
  315.  
  316.  
  317.  
  318.  
  319.  
  320. #endif
  321.